package com.gelsanalyzer;

import java.io.*;

import javax.xml.bind.*;

import com.gelsanalyzer.business.*;

// import com.gelsanalyzer.data.*;
/*
 * TestDataMarshalling is a simple test of concept to check the feasibility of
 * using code generators to generate our object code for the DAL in our project.
 * Last modified by JO on: 1/19/2008
 */

public class TestDataMarshalling {

    public static void main(String[] args) {

        // Courses courses = new Courses();
        // List<Course> course = courses.getCourse();
        // course.add(new Course());
        //
        // List<Gels> gels = courses.getCourse().get(0).getGels();
        // gels.add(new Gels());
        // gels.get(0).setNum(5);
        //
        // System.out.println("I'm cooking with gas now!!!!");
        //        
        // course.get(0).setDepartment("MATH");
        // course.get(0).setDescription("Calculus II with a 70% attrition
        // Rate");
        // course.get(0).setNumber(BigInteger.valueOf(321));
        //Course course = new CourseHome().findById(100);
        Courses courses = new Courses();
        courses.setCourse(new CourseHome().findAllCourses());

        try {
            JAXBContext context = JAXBContext
                .newInstance("com.gelsanalyzer.business");

            FileWriter fileWriter = new FileWriter("data/test.xml", false);
            fileWriter.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
            fileWriter.append("<?xml-stylesheet type=\"text/xsl\" href=\"departments2.xsl\"?>\n");
            
            Marshaller marshaller = context.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
            marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            marshaller.marshal(courses, fileWriter);

        } catch ( JAXBException e ) {
            e.printStackTrace(System.out);
        } catch ( IOException x ) {
            x.printStackTrace(System.out);
        }
    }
}
